/*   1:    */ package org.intellij.plugins.relaxNG.convert;
/*   2:    */ 
/*   3:    */

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ArrayUtil;
import com.thaiopensource.relaxng.edit.SchemaCollection;
import com.thaiopensource.relaxng.input.InputFailedException;
import com.thaiopensource.relaxng.input.InputFormat;
import com.thaiopensource.relaxng.input.MultiInputFormat;
import com.thaiopensource.relaxng.input.dtd.DtdInputFormat;
import com.thaiopensource.relaxng.input.parse.compact.CompactParseInputFormat;
import com.thaiopensource.relaxng.input.parse.sax.SAXParseInputFormat;
import com.thaiopensource.relaxng.input.xml.XmlInputFormat;
import com.thaiopensource.relaxng.output.LocalOutputDirectory;
import com.thaiopensource.relaxng.output.OutputDirectory.Stream;
import com.thaiopensource.relaxng.output.OutputFailedException;
import com.thaiopensource.relaxng.output.OutputFormat;
import com.thaiopensource.relaxng.output.dtd.DtdOutputFormat;
import com.thaiopensource.relaxng.output.rnc.RncOutputFormat;
import com.thaiopensource.relaxng.output.rng.RngOutputFormat;
import com.thaiopensource.relaxng.output.xsd.XsdOutputFormat;
import com.thaiopensource.relaxng.translate.util.InvalidParamsException;
import com.thaiopensource.util.UriOrFile;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */
/*  22:    */
/*  23:    */
/*  24:    */
/*  25:    */
/*  26:    */
/*  27:    */
/*  28:    */
/*  29:    */
/*  30:    */
/*  31:    */
/*  32:    */
/*  33:    */
/*  34:    */
/*  35:    */ 
/*  36:    */ public class IdeaDriver
/*  37:    */ {
/*  38:    */   private static final int a = 72;
/*  39:    */   private static final int b = 2;
/*  40:    */   private final ConvertSchemaSettings c;
/*  41:    */   private final Project d;
/*  42:    */   
/*  43:    */   public IdeaDriver(ConvertSchemaSettings paramConvertSchemaSettings, Project paramProject)
/*  44:    */   {
/*  45: 60 */     this.c = paramConvertSchemaSettings;
/*  46: 61 */     this.d = paramProject;
/*  47:    */   }
/*  48:    */   
/*  49:    */   public void convert(SchemaType paramSchemaType, IdeaErrorHandler paramIdeaErrorHandler, VirtualFile... paramVarArgs)
/*  50:    */   {
/*  51: 66 */     if (paramVarArgs.length == 0) {
/*  52: 67 */       throw new IllegalArgumentException();
/*  53:    */     }
/*  54:    */     try
/*  55:    */     {
/*  56: 71 */       InputFormat localInputFormat = b(paramSchemaType);
/*  57: 72 */       if ((paramVarArgs.length > 1) && 
/*  58: 73 */         (!(localInputFormat instanceof MultiInputFormat))) {
/*  59: 74 */         throw new IllegalArgumentException();
/*  60:    */       }
/*  61: 78 */       VirtualFile localVirtualFile = paramVarArgs[0];
/*  62: 79 */       SchemaType localSchemaType = this.c.getOutputType();
/*  63: 80 */       String str1 = localSchemaType.toString().toLowerCase();
/*  64:    */       
/*  65: 82 */       ArrayList localArrayList = new ArrayList();
/*  66: 84 */       if (paramSchemaType != SchemaType.DTD)
/*  67:    */       {
/*  68: 85 */         localObject1 = localVirtualFile.getCharset();
/*  69: 86 */         if (localObject1 != null) {
/*  70: 87 */           localArrayList.add("encoding=" + ((Charset)localObject1).name());
/*  71:    */         }
/*  72:    */       }
/*  73: 91 */       Object localObject1 = new ArrayList();
/*  74: 92 */       this.c.addAdvancedSettings(localArrayList, (List)localObject1);
/*  75:    */       
/*  76:    */ 
/*  77:    */ 
/*  78:    */ 
/*  79:    */ 
/*  80: 98 */       String str2 = localVirtualFile.getPath();
/*  81: 99 */       String str3 = UriOrFile.toUri(str2);
/*  82:    */       Object localObject2;
/*  83:    */       SchemaCollection localSchemaCollection;
/*  84:    */       try
/*  85:    */       {
/*  86:101 */         if ((localInputFormat instanceof MultiInputFormat))
/*  87:    */         {
/*  88:102 */           MultiInputFormat localMultiInputFormat = (MultiInputFormat)localInputFormat;
/*  89:103 */           localObject2 = new String[paramVarArgs.length];
/*  90:104 */           for (int i = 0; i < paramVarArgs.length; i++) {
/*  91:105 */             localObject2[i] = UriOrFile.toUri(paramVarArgs[i].getPath());
/*  92:    */           }
/*  93:107 */           localSchemaCollection = localMultiInputFormat.load((String[])localObject2, ArrayUtil.toStringArray(localArrayList), str1, paramIdeaErrorHandler);
/*  94:    */         }
/*  95:    */         else
/*  96:    */         {
/*  97:109 */           localSchemaCollection = localInputFormat.load(str3, ArrayUtil.toStringArray(localArrayList), str1, paramIdeaErrorHandler);
/*  98:    */         }
/*  99:    */       }
/* 100:    */       catch (IOException localIOException1)
/* 101:    */       {
/* 102:112 */         paramIdeaErrorHandler.fatalError(new SAXParseException(localIOException1.getMessage(), null, str3, -1, -1, localIOException1));
/* 103:113 */         return;
/* 104:    */       }
/* 105:116 */       File localFile = new File(this.c.getOutputDestination());
/* 106:    */       int k;
/* 107:118 */       if (localFile.isDirectory())
/* 108:    */       {
/* 109:119 */         String str4 = new File(str2).getName();
/* 110:120 */         k = str4.lastIndexOf('.');
/* 111:121 */         localObject2 = new File(localFile, (k > 0 ? str4.substring(0, k) : str4) + "." + str1);
/* 112:    */       }
/* 113:    */       else
/* 114:    */       {
/* 115:123 */         localObject2 = localFile;
/* 116:    */       }
/* 117:    */       try
/* 118:    */       {
/* 119:127 */         int j = this.c.getIndent();
/* 120:128 */         k = this.c.getLineLength();
/* 121:129 */         LocalOutputDirectory local1 = new LocalOutputDirectory(localSchemaCollection.getMainUri(), (File)localObject2, "." + str1, this.c.getOutputEncoding(), k > 0 ? k : 72, j > 0 ? j : 2)
/* 122:    */         {
/* 123:    */           public OutputDirectory.Stream open(String paramAnonymousString1, String paramAnonymousString2)
/* 124:    */             throws IOException
/* 125:    */           {
/* 126:137 */             String str1 = super.reference(null, paramAnonymousString1);
/* 127:138 */             File localFile = new File(this.val$outputFile.getParentFile(), str1);
/* 128:139 */             if (localFile.exists())
/* 129:    */             {
/* 130:140 */               String str2 = "The file '" + localFile.getAbsolutePath() + "' already exists. Overwrite it?";
/* 131:141 */               int i = Messages.showYesNoDialog(IdeaDriver.this.d, str2, "Output File Exists", Messages.getWarningIcon());
/* 132:142 */               if (i == 0) {
/* 133:143 */                 return super.open(paramAnonymousString1, paramAnonymousString2);
/* 134:    */               }
/* 135:144 */               if (i == 1) {
/* 136:145 */                 throw new IdeaDriver.CanceledException(null);
/* 137:    */               }
/* 138:    */             }
/* 139:148 */             return super.open(paramAnonymousString1, paramAnonymousString2);
/* 140:    */           }
/* 141:151 */         };
/* 142:152 */         OutputFormat localOutputFormat = a(this.c.getOutputType());
/* 143:    */         
/* 144:154 */         localOutputFormat.output(localSchemaCollection, local1, ArrayUtil.toStringArray((Collection)localObject1), paramSchemaType.toString().toLowerCase(), paramIdeaErrorHandler);
/* 145:    */       }
/* 146:    */       catch (IOException localIOException2)
/* 147:    */       {
/* 148:156 */         paramIdeaErrorHandler.fatalError(new SAXParseException(localIOException2.getMessage(), null, UriOrFile.fileToUri((File)localObject2), -1, -1, localIOException2));
/* 149:    */       }
/* 150:    */     }
/* 151:    */     catch (CanceledException localCanceledException) {}catch (SAXParseException localSAXParseException)
/* 152:    */     {
/* 153:161 */       paramIdeaErrorHandler.error(localSAXParseException);
/* 154:    */     }
/* 155:    */     catch (MalformedURLException localMalformedURLException)
/* 156:    */     {
/* 157:163 */       Logger.getInstance(getClass().getName()).error(localMalformedURLException);
/* 158:    */     }
/* 159:    */     catch (InputFailedException localInputFailedException) {}catch (InvalidParamsException localInvalidParamsException) {}catch (OutputFailedException localOutputFailedException) {}catch (SAXException localSAXException) {}
/* 160:    */   }
/* 161:    */   
/* 162:    */   private OutputFormat a(SchemaType paramSchemaType)
/* 163:    */   {
/* 164:177 */     switch (2.$SwitchMap$org$intellij$plugins$relaxNG$convert$SchemaType[paramSchemaType.ordinal()])
/* 165:    */     {
/* 166:    */     case 1: 
/* 167:179 */       return new DtdOutputFormat();
/* 168:    */     case 2: 
/* 169:181 */       return new RncOutputFormat();
/* 170:    */     case 3: 
/* 171:183 */       return new RngOutputFormat();
/* 172:    */     case 4: 
/* 173:185 */       return new XsdOutputFormat();
/* 174:    */     }
/* 175:187 */     if (!$assertionsDisabled) {
/* 176:187 */       throw new AssertionError("Unsupported output type: " + paramSchemaType);
/* 177:    */     }
/* 178:188 */     return null;
/* 179:    */   }
/* 180:    */   
/* 181:    */   private InputFormat b(SchemaType paramSchemaType)
/* 182:    */   {
/* 183:193 */     switch (2.$SwitchMap$org$intellij$plugins$relaxNG$convert$SchemaType[paramSchemaType.ordinal()])
/* 184:    */     {
/* 185:    */     case 1: 
/* 186:195 */       return new DtdInputFormat();
/* 187:    */     case 2: 
/* 188:197 */       return new CompactParseInputFormat();
/* 189:    */     case 3: 
/* 190:199 */       return new SAXParseInputFormat();
/* 191:    */     case 5: 
/* 192:201 */       return new XmlInputFormat();
/* 193:    */     }
/* 194:203 */     if (!$assertionsDisabled) {
/* 195:203 */       throw new AssertionError("Unsupported input type: " + paramSchemaType);
/* 196:    */     }
/* 197:204 */     return null;
/* 198:    */   }
/* 199:    */   
/* 200:    */   private static class CanceledException
/* 201:    */     extends RuntimeException
/* 202:    */   {}
/* 203:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.plugins.relaxNG.convert.IdeaDriver

 * JD-Core Version:    0.7.0.1

 */